package research;

import java.util.ArrayList;
import java.util.List;

import db.beans.M_CategoryBean;


public class CategoryTree {
	
	private CategoryTree parent = null;
	
	private Long parentCategoryCode = null;

	private List<CategoryTree> child = null;
	
	private int depth = 0;
	
	private M_CategoryBean category;
	
	private int maxDepth = 0;
	
	public CategoryTree(){
		
	}
	
	public CategoryTree(CategoryTree parent, CategoryTree child, M_CategoryBean category, int depth){
		this.parent = parent;
    	if (this.child == null){
    		this.child = new ArrayList<CategoryTree>();
    	}
    	this.child.add(child);
		this.category = category;
		this.depth = depth;
		
	}
	public void setParent(CategoryTree parent){
    	this.parent = parent;
    }
	
    public CategoryTree getParent(){
    	return this.parent;
    }
    
	
	public Long getParentCategoryCode() {
		return parentCategoryCode;
	}

	public void setParentCategoryCode(Long parentCategoryCode) {
		this.parentCategoryCode = parentCategoryCode;
	}
    
    public void addChild(CategoryTree child){
    	if (this.child == null){
    		this.child = new ArrayList<CategoryTree>();
    	}
    	this.child.add(child);
    }
    
    public List<CategoryTree> getChild(){
    	return child;
    }
    
    public void setDepth(int depth){
    	this.depth = depth;
    }
    
    public int getDepth(){
    	return this.depth;
    }
    
    public M_CategoryBean getCategory() {
		return category;
	}

	public void setCategory(M_CategoryBean category) {
		this.category = category;
	}
	
    public CategoryTree getTopCategory(){
    	if (this.parent == null){
    		return this;
    	} 
    	this.parent.getTopCategory();
    	return null;
    }
    
    public int getCategoryDepth(){
    	CategoryTree t = getTopCategory();
    	return t.getMaxDepth();
    }
    
	public void setMaxDepth(int maxDepth) {
		this.maxDepth = maxDepth;
	}
	
    public int getMaxDepth(){
    	return this.maxDepth;
    }
    
}
